package user

import (
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/http_server/controller"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/common/errcode"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/service/base/user"
	"github.com/gin-gonic/gin"
)

type UserController struct {
	controller.BaseController
	userNewService user.UserNewServiceIface
}

// NewUserController
// 构造函数
func NewUserController(
	userNewService user.UserNewServiceIface,
) *UserController {
	return &UserController{
		userNewService: userNewService,
	}
}

// RegisterRouter
// 注册路由
func (c *UserController) RegisterRouter(g *gin.RouterGroup) {
	g.GET("user/all-user", c.allUser)
	// 全量用户带组织架构列表
	g.GET("user/org-and-all-user", c.getOrgAndAllUser)
}

func (c *UserController) allUser(ctx *gin.Context) {
	resp, err := c.userNewService.GetAllUserList(ctx)
	if err != nil {
		c.Fail(ctx, errcode.COMMON_ERROR, err.Error())
		return
	}

	c.Success(ctx, resp)
}

func (c *UserController) getOrgAndAllUser(ctx *gin.Context) {
	resp, err := c.userNewService.GetAllUserWithOrganization(ctx)
	if err != nil {
		c.Fail(ctx, errcode.COMMON_ERROR, err.Error())
		return
	}

	c.Success(ctx, resp)
}
